home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 050a.dms / 050a.adf / TEXTS / chapter07.txt < prev    next >
Text File  |  1992-02-26  |  12KB  |  356 lines

  1.                      The Absolute Beginners Guide To Amos
  2.                     -------------------------------------
  3.                                 Chapter Seven
  4.                                 -------------
  5.  
  6. Before we start, here are the answers to the quiz in chapter six.
  7.  
  8.                        1. B      2. A
  9.                        3. C      4. A
  10.                        5. B      6. A
  11.                        7. A      8. B
  12.                        9. A     10. A
  13.  
  14. If you got less than five correct then please re-read the corresponding
  15. chapters. If you got five to eight correct you are doing great if you got
  16. nine or more congratulations and keep it up.
  17. ---------------------------------------------------------------------------
  18.  
  19. Now I think it`s time to learn some new commands I have picked out some
  20. commands that are fairly straight forward and some others that are a bit more
  21. complex, but they are commands that you are going to need to know about.  
  22. You shouldn`t have too much trouble with this lot. Keep making those notes 
  23. and refer to them as much as needed.  I have been using Stos/Amos for quite 
  24. a few years now and I still refer to my note book, especially for things like
  25. the Amos file selector syntax. I can never remember how that goes. 
  26. Anyway enough yapping let`s learn something new.
  27.  
  28.  
  29. BOOM
  30. ----
  31. This is fun, BOOM is one of three sound effects already built into Amos for 
  32. us.  It doesn`t need any variables and is a stand alone command. You just
  33. simply put BOOM anywhere in your program that you want a BOOM sound, such as
  34. an explosion for example.  Admittedly BOOM doesn`t sound that great but it is
  35. simple and memory efficient.
  36.  
  37. BELL
  38. ----
  39. The same as BOOM except giving a simple single bell sound.
  40.  
  41. SHOOT
  42. -----
  43. Again the same as above but can be used as a gun firing sound effect.
  44.  
  45. EXAMPLE7.Amos will give you an idea of how to use these effects.
  46.  
  47.  
  48. WAIT N
  49. -------
  50. This command is almost identical to WAIT KEY but more flexible. T
  51. he N stands for a number, any number, for example, WAIT 50, would halt the
  52. program in it`s tracks for one second and then continue executing from the
  53. next command or line.  
  54. WAIT has nothing to do with key presses or the user so put that out of your 
  55. mind now.  WAIT just WAITs around for N 50ths of a second. Some examples:
  56.  
  57. WAIT 1    REM Wait for 1/50th of a second
  58.  
  59. WAIT 25   REM Wait for half a second
  60.  
  61. WAIT 50   REM wait for one second
  62.  
  63. WAIT 100  REM Wait for two seconds
  64.  
  65. WAIT 500  REM Wait for ten seconds.
  66.  
  67. And so on and so forth.
  68.  
  69.  
  70. RND (N)
  71. -------
  72. RND is short for RANDOM this smart little fellow generates RaNDom numbers for
  73. us in any range we want. I will explain by example:
  74.  
  75.  
  76. RND (5)     REM Will produce a random number from 0 to 4 (but not 5)
  77.  
  78.  
  79. RND (5)+1   REM Will give a random number from 1 to 5, it is the same as
  80.                 above but 1 is added to the result (+1)
  81.  
  82. RND (100)   REM Generates a random number from 0 to 99, if we wanted it to 
  83.                 include 100 in it`s calculations we just add a +1
  84.  
  85. RND (100)+1 REM Like this.
  86.  
  87.  
  88.   
  89. That`s all very well but to use a RaNDom number we will need to assign it to
  90. a variable so we can manipulate it. Luckily, that is quite easy:
  91.  
  92. A=RND(5)     REM A equals a random number 0 to 4
  93.  
  94.  
  95. A=RND (5)+1  REM A equals a random number 1 to 5
  96.  
  97.  
  98. A=RND (100)  REM A equals a random number 0 to 99
  99.  
  100.  
  101. A=RND(100)+1 REM A equals a random number 1 to 100
  102.  
  103.  
  104. A, of course, can be any variable name you wish like GUESS or RN etc.
  105.  
  106. So, we have a variable containing a random number, we know the range of the
  107. number but we will have to interrogate the variable to find out the generated
  108. random number because it won`t tell us unless we ask:
  109.  
  110. IF A=1 then BOOM   REM IF the variable A is equal to one then play the 
  111.                        BOOM sound effect.
  112.  
  113. Well that is one way of finding out if the random number is equal to one,
  114. but that approach is pretty limited.
  115.  
  116. Let`s suppose we have a simple guessing game where the computer generates
  117. a RaNDom number from 0 to 99, the user then INPUTS his guess and the 
  118. computer responds with a TOO LOW, TOO HIGH or CORRECT message.
  119. How do we get Amos to check for higher, lower and equal to the RaNDom number?
  120.  
  121.  
  122. IF GUESS=RN then bell  REM GUESS is the users INPUT, RN the computers
  123.                            RaNDom number, if equal sound the BELL effect.
  124.  
  125. It`s the equals sign that does it.
  126.  
  127.  
  128.  
  129. How about higher or lower?
  130.  
  131. IF GUESS>RN THEN  BOOM    REM If GUESS is more than the RaNDom number 
  132.                               THEN sound the BOOM effect.
  133.  
  134.  IF GUESS <RN THEN SHOOT   REM If GUESS is less than RN THEN SHOOT
  135.  
  136.  
  137.  
  138. Notice in the last example how close the line of code is to the actual
  139. English translation.
  140.  
  141.  
  142.  
  143. Here is the listing of the number guessing game which is EXAMPLE7.Amos
  144.  
  145.  
  146. REM Number Guess
  147. `
  148. `
  149. PAPER 0: HIDE : CLS 0
  150. SCORE=0
  151. L1:
  152. RN=RND(100)
  153. L2:
  154. CLS 0
  155. LOCATE 0,0: PRINT "SCORE ";score
  156. LOCATE 0,4: LINE INPUT "What is your guess? (0-99) ";guess
  157. IF GUESS=RN THEN LOCATE 0,20:PRINT "CORRECT":BELL:INC SCORE:WAIT 100: GOTO L1
  158. IF GUESS>RN THEN LOCATE 0,20: PRINT "TOO HIGH": SHOOT: WAIT 100: GOTO L2
  159. IF GUESS<RN THEN LOCATE 0,20: PRINT "TOO LOW": BOOM: WAIT 100:GOTO L2
  160. REM Amos will never get to this line! Do you know why?
  161.  
  162.  
  163. Don`t panic there are some new commands to cover here that we haven`t looked
  164. at yet, here is the breakdown of every part of EXAMPLE7.Amos, 
  165.  
  166. PAPER 0: HIDE: CLS 0
  167. --------------------
  168. We know all about these.
  169.  
  170.  
  171. SCORE=0
  172. -------
  173. Set the variable SCORE to 0.  We have covered variables previously.
  174.  
  175.  
  176. L1:
  177. ---
  178. This is the first part of the program we haven`t seen before.
  179. L1 is a Label it`s not a command as such, it is a marker, so that later on we
  180. can tell Amos to GOTO the marker if certain conditions are met.  
  181. The use of labels will become clear in a minute when we take a look at the 
  182. infamous GOTO instruction. 
  183. A few things to remember about labels is they must end in a colon, like this,
  184.  
  185. LABEL: 
  186.  
  187. And they can contain any string of text or numbers including the underscore 
  188. character like this 
  189.  
  190. LABEL_1:
  191.  
  192.  
  193. RN=RND (100)
  194. -----------
  195. This line is explained earlier in this chapter.
  196.  
  197.  
  198. L2:
  199. --
  200. Is the second label, we have to make sure labels are not the same, we can`t
  201. have L1: twice so to keep it simple I`ve used L2:
  202.  
  203.  
  204. CLS 0
  205. -----
  206. You know what this does. If not look at EXAMPLE7.Amos
  207.  
  208.  
  209. LOCATE 0,0: 
  210. ----------
  211. This is another new command we haven`t yet covered.  LOCATE literally LOCATES
  212. the coordinates you give it and sets the text cursor to that position on the 
  213. screen and anything PRINTed after the LOCATE instruction will be PRINTed at
  214. the text coordinate supplied.  In the above line the coordinates we have
  215. supplied LOCATE with are 0 and 0 this means, starting from the top left edge
  216. of the screen, 0 across and 0 down so in effect we are telling Amos to set
  217. the PRINTing position to the top left edge of the screen. Think of the
  218. screen as a grid. The default screen used by Amos has 40 cells across the
  219. screen and 32 down the screen. Each cell is 8 by 8 pixels which can hold
  220. a character. A character is a letter or number if you like. So the letters
  221. ABCD are four characters. So in effect you can have 40 letters or numbers
  222. going across the screen and 32 down the screen. If you go to the Amos
  223. editor and type in PRINT "1234567890123456789012345678901234567890" press 
  224. return then F1 to run it and  you will see the 40 numbers fit exactly across
  225. the screen. If you then put LOCATE 0,10 before your PRINT statement the 40
  226. numbers would be printed ten spaces down the screen. Try it out and you will 
  227. soon understand. Also try LOCATEing different widths and using different 
  228. lengths of text in your PRINT statement.  
  229.  
  230.  
  231. PRINT "SCORE ";SCORE
  232. --------------------
  233. The next part of the line uncovers two features of Amos we have looked at 
  234. separately but not glued together in this form.  What is happening here is we
  235. Are telling the PRINT command to PRINT the word SCORE plus a space and then 
  236. telling Amos to get ready for a variable with the ; We then supply the 
  237. variable which is the SCORE variable we defined to 0 at the start of the
  238. program.  Can you work out what the screen would look like if SCORE=7?
  239. It would look like this:
  240.  
  241. SCORE 7  
  242.  
  243. If you thought it would look like this:
  244.  
  245. SCORE SCORE 7
  246.  
  247. Then you must understand that the first word is enclosed in quotes which as
  248. we discussed earlier means that Amos will PRINT exactly what is inside the 
  249. quotes the second word SCORE is a variable which in this example equalled
  250. 7 so Amos PRINTED the value of SCORE and not the actual string.
  251.  
  252.  
  253. LOCATE 0,4: 
  254. ----------
  255. The same as above but sets the PRINT position to 0 across 4 down.
  256.  
  257.  
  258. LINE INPUT "What is your guess? (0-99) ";guess
  259. ----------------------------------------------
  260. We have discussed LINE INPUT quite thoroughly before. Check your notes and
  261. read the REMs in EXAMPLE7.Amos
  262.  
  263.  
  264. I shall break the next line up into two.
  265.  
  266. IF GUESS=RN THEN LOCATE 0,2: PRINT "CORRECT"
  267. --------------------------------------------
  268.  
  269. IF the variable GUESS (The players number, taken from the LINE INPUT)
  270. is equal to RN (RN is the RaNDom number generated earlier) THEN set the
  271. PRINT position to 0 cells across and 2 cells down the screen, then PRINT
  272. the string of characters in quotes "CORRECT"
  273.  
  274. BELL: INC SCORE: WAIT 100: GOTO L1
  275. ---------------------------------- 
  276. The second part of the line continues with, make the BELL sound, INCrement
  277. the players SCORE by one, wait 2 seconds then GOTO the label marked L1.
  278. Notice we don't put GOTO L1: (I.e. no colon)
  279.  
  280. The GOTO command is the only stranger here and must be the most controversial
  281. command in any programming language ever.  Some hate to use it some don`t 
  282. care, some swear by it.  At this stage of your learning I wouldn`t worry 
  283. about it at all.  As far as I am concerned I will use a GOTO if it is 
  284. necessary or if it keeps the program simple.  Sometime In the future I guess 
  285. you will come to your own decision about using the GOTO command or not.  
  286. Personally I can`t see what all the fuss is about. So basically GOTO simply 
  287. goes to the label you have told it to and carries on executing the program 
  288. from there.
  289.  
  290. Everything in the next two lines of the program have been explained except
  291. the operators < and >. These signs simply mean.
  292.  
  293. >    More than 
  294.  
  295. <    Less than 
  296.  
  297. Examples:
  298.  
  299. IF Jim's age is > Mary's age THEN Jim is older             
  300.                 |
  301.                 |
  302.              MORE THAN
  303.  
  304.  
  305.  
  306. IF 12 < 14 THEN BELL
  307.       |
  308.       |
  309.    LESS THAN
  310.  
  311.  
  312.  
  313. You can use them both together as well, like this:
  314.  
  315. IF 12 <> 14 THEN BELL
  316.       |
  317.       |
  318. MORE THAN OR LESS THAN
  319. (In other words if 12 doesn't = 14)
  320.  
  321.  
  322.  
  323. You can even use the equality sign as well:
  324.  
  325. IF 12 >= 14 THEN BELL
  326.       |
  327.       |
  328. MORE THAN OR EQUAL TO
  329.  
  330.  
  331.  
  332. But you can't use all three like this:
  333.  
  334. IF 12 <=> 14 THEN BELL   * SYNTAX ERROR *
  335.  
  336. You may have noticed that the number guessing program has no quit option 
  337. or an end. I have done this purposefully for two reasons. 1. To keep it as
  338. simple as possible and 2. To remind you that to break into an Amos program
  339. you simply hold down the Ctrl key and press C on your keyboard. The only
  340. time this will not work is if you have implement the BREAK command in your
  341. program. BREAK will be covered in a later chapter.
  342. Another feature sorely lacking in our number guessing game is the ability
  343. to keep track of how many attempts it took for the player to guess the 
  344. number. Why don't you have a go. A few hints to help you do this.
  345.  
  346. You will need to store the amount of attempts in a variable, you could call
  347. it ATTEMPTS for simplicity. Don't forget to set ATTEMPTS to zero when the
  348. player starts another game. You will also need to PRINT ATTEMPTS somewhere.
  349.  
  350. So that wraps up this chapter. I hope you remembered to take notes on this
  351. lot as we have exams coming up for you very soon! Now is a good time to load
  352. up EXAMPLE7.Amos.
  353.  
  354.                             End of chapter seven
  355.                             ^^^^^^^^^^^^^^^^^^^^
  356.